﻿package mortal.game.view.heroArena.view
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class HeroArenaFightInfoSpr extends GSprite
    {
        private var _proxyName:GTextFiled;
        private var _roleName:GTextFiled;
        private var _career:GTextFiled;
        private var _bloodBar:BaseProgressBar;
        private var _combat:GTextFiled;
        private var _headIcon:GImageBitmap;
        private var _stateTxt:GTextFiled;
        private var _playerInfo:EntityInfo;
        private var _entityId:SEntityId;
        private var _playerName:String;
        private var _isAddListener:Boolean;
        private var _isDead:Boolean;

        public function HeroArenaFightInfoSpr()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._headIcon = UIFactory.gImageBitmap("", -31 + 10, 20 + 6, this);
            this._proxyName = UIFactory.gTextField("", 0, 2, 61, 25, this, GlobalStyle.textFormatHuang.setSize(13));
            this._roleName = UIFactory.gTextField("", 46, 2, 108, 25, this, GlobalStyle.textFormatLv.setSize(13));
            this._roleName.configEventListener(MouseEvent.CLICK, this.onLinkClickHandler);
            this._roleName.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._roleName.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._career = UIFactory.gTextField("", 147 - 2, 2, 57, 25, this, GlobalStyle.textFormatHuang.setSize(13));
            this._stateTxt = UIFactory.gTextField("", -13, 47, 52, 20, this, GlobalStyle.textFormatHong);
            this._bloodBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._bloodBar.setBg(ImagesConst.PetLifeBg, true, 85, 13);
            this._bloodBar.setProgress(ImagesConst.GuildWarSelfProgress, true, (2 - 1), (1 + 1), 83, 10);
            this._bloodBar.setLabel(BaseProgressBar.ProgressBarTextPercent, 27, -4, 35, 20, GlobalStyle.textFormatBai);
            this._bloodBar.setValue(0, 100);
            this._bloodBar.x = 90 + 7;
            this._bloodBar.y = 44 + 7;
            this.addChild(this._bloodBar);
            this._combat = UIFactory.gTextField("", 94, 68, 71, 25, this, GlobalStyle.textFormatBai.setSize(13));
            return;
        }// end function

        private function onLinkClickHandler(event:Event) : void
        {
            if (this._entityId)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LookPlayerInfo, this._entityId));
            }
            return;
        }// end function

        public function set data(param1:EntityInfo) : void
        {
            var _loc_2:String = null;
            var _loc_3:String = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            this._playerInfo = param1;
            if (this._playerInfo)
            {
                _loc_2 = NameUtil.getProxyName(this._playerInfo.entityInfo.entityId, true);
                _loc_3 = this._playerInfo.entityInfo.name;
                _loc_4 = this._playerInfo.entityInfo.career;
                _loc_5 = this._playerInfo.entityInfo.sex;
                this._proxyName.text = _loc_2;
                this._roleName.htmlText = HTMLUtil.addLink(_loc_3, GlobalStyle.colorLv);
                this._roleName.x = this._proxyName.x + this._proxyName.textWidth + 2;
                this._career.htmlText = "[" + GameDefConfig.instance.getECareerNameAddColoer(_loc_4) + "]";
                this._career.x = this._roleName.x + this._roleName.textWidth + 10;
                this._combat.text = this._playerInfo.entityInfo.combat + "";
                this._bloodBar.setValue(this._playerInfo.entityInfo.life, this._playerInfo.entityInfo.maxLife);
                this._headIcon.imgUrl = AvatarUtil.getPlayerAvatarUrl(_loc_4, _loc_5, AvatarUtil.Mid);
                this._headIcon.filters = [];
                this._stateTxt.text = "";
                this._entityId = new SEntityId();
                this._entityId.id = this._playerInfo.entityInfo.entityId.id;
                this._entityId.type = this._playerInfo.entityInfo.entityId.type;
                this._entityId.typeEx = this._playerInfo.entityInfo.entityId.typeEx;
                this._entityId.typeEx2 = this._playerInfo.entityInfo.entityId.typeEx2;
                if (!this._isAddListener)
                {
                    this.addListeners();
                }
            }
            return;
        }// end function

        public function clear() : void
        {
            this._bloodBar.setValue(0, 100);
            this._stateTxt.htmlText = HTMLUtil.addColor(Language.getString(41546), GlobalStyle.colorHong);
            this._headIcon.filters = [FilterConst.colorFilter2];
            this._isDead = true;
            if (this._isAddListener)
            {
                this.removeListeners();
            }
            return;
        }// end function

        private function getCareerShortName(param1:int) : String
        {
            var _loc_2:String = null;
            switch(param1)
            {
                case ECareer._ECareerWarrior:
                {
                    _loc_2 = Language.getString(21518);
                    break;
                }
                case ECareer._ECareerArcher:
                {
                    _loc_2 = Language.getString(21519);
                    break;
                }
                case ECareer._ECareerMage:
                {
                    _loc_2 = Language.getString(21520);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        private function addListeners() : void
        {
            if (this._playerInfo)
            {
                this._playerInfo.addEventListener(EntityInfoEventName.UpdateLife, this.updateLife);
                this._playerInfo.addEventListener(EntityInfoEventName.Dead, this.updateDeathState);
                this._isAddListener = true;
            }
            return;
        }// end function

        private function removeListeners() : void
        {
            if (this._playerInfo)
            {
                this._playerInfo.removeEventListener(EntityInfoEventName.UpdateLife, this.updateLife);
                this._playerInfo.removeEventListener(EntityInfoEventName.Dead, this.updateDeathState);
                this._isAddListener = false;
            }
            return;
        }// end function

        private function updateLife(event:Event) : void
        {
            if (this._isDead)
            {
                return;
            }
            if (this._bloodBar)
            {
                this._bloodBar.setValue(this._playerInfo.entityInfo.life, this._playerInfo.entityInfo.maxLife);
            }
            return;
        }// end function

        private function updateDeathState(event:Event) : void
        {
            this._bloodBar.setValue(0, 100);
            this._stateTxt.htmlText = HTMLUtil.addColor(Language.getString(41546), GlobalStyle.colorHong);
            this._headIcon.filters = [FilterConst.colorFilter2];
            this._isDead = true;
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        public function get playerInfo() : EntityInfo
        {
            return this._playerInfo;
        }// end function

        public function get entityId() : SEntityId
        {
            return this._entityId;
        }// end function

        public function get roleName() : String
        {
            return this._roleName.text;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._proxyName.dispose();
            this._proxyName = null;
            this._roleName.dispose();
            this._roleName = null;
            this._career.dispose();
            this._career = null;
            this._bloodBar.dispose();
            this._bloodBar = null;
            this._combat.dispose();
            this._combat = null;
            this._headIcon.dispose();
            this._headIcon = null;
            this._stateTxt.dispose();
            this._stateTxt = null;
            this.removeListeners();
            this._playerInfo = null;
            this._entityId = null;
            this._isAddListener = false;
            this._isDead = false;
            return;
        }// end function

    }
}
